//
//  ADCDN_ViewController.m
//  ADCDN_APP
//
//  Created by 吃不胖的瘦子 on 2021/2/24.
//  Copyright © 2021 llh. All rights reserved.
//

#import "ADCDN_ViewController.h"
#import "ADCDN_SplashViewController.h"
#import "ADCDN_BannerViewController.h"
#import "ADCDN_InterstitialViewController.h"
#import "ADCDN_NativeViewController.h"
#import "ADCDN_VideoViewController.h"
#import "ADCDN_GameTaskViewController.h"
@interface ADCDN_ViewController ()

@end

@interface ADCDN_ViewController ()<UITableViewDelegate,UITableViewDataSource>
/** tableView */
@property (nonatomic,strong) UITableView *menuTB;
/** titleArr */
@property(copy,nonatomic)NSArray *menuTitleArr;


@end

@implementation ADCDN_ViewController
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    //游戏控制器会隐藏导航栏 返回时需重新设置下导航栏
    [self.navigationController setNavigationBarHidden:NO animated:animated];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title = @"ADCDN_demo";
    
    [self menuTB];
    
}

-(UITableView *)menuTB{
    if (!_menuTB) {
        _menuTB = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, ScreenW, ScreenH - [self getStatusBarHeight] - [self getNavigationBarHeight]) style:UITableViewStylePlain];
        _menuTB.delegate = self;
        _menuTB.dataSource = self;
        _menuTB.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
        [self.view addSubview:_menuTB];
    }
    return _menuTB;
}
-(NSArray *)menuTitleArr{
    if (!_menuTitleArr) {
        _menuTitleArr = @[@"开屏广告",@"原生广告",@"横幅广告",@"插屏广告",@"模版视频广告2.0",@"果园游戏"];
    }
    return _menuTitleArr;
}
/**
 *  获取状态栏高度
 */
-(CGFloat)getStatusBarHeight{
    return [[UIApplication sharedApplication] statusBarFrame].size.height;
}
/**
 *  获取导航栏高度
 */
-(CGFloat)getNavigationBarHeight{
    return self.navigationController.navigationBar.frame.size.height;
}
/**
 *  UITableViewDelegate,UITableViewDataSource
 */
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.menuTitleArr.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
    }
    cell.textLabel.text = [NSString stringWithFormat:@"%@", self.menuTitleArr[indexPath.row]];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    // 开屏广告
    if (indexPath.row == 0) {
        NSLog(@"点击%@",self.menuTitleArr[indexPath.row]);
        ADCDN_SplashViewController *vc = [ADCDN_SplashViewController new];
        [self.navigationController pushViewController:vc animated:YES];
    }
    // 原生广告
    if (indexPath.row == 1) {
        NSLog(@"点击%@",self.menuTitleArr[indexPath.row]);
        ADCDN_NativeViewController *vc = [ADCDN_NativeViewController new];
        [self.navigationController pushViewController:vc animated:YES];
    }
    // 横幅广告
    if (indexPath.row == 2) {
        NSLog(@"点击%@",self.menuTitleArr[indexPath.row]);
        ADCDN_BannerViewController *vc = [ADCDN_BannerViewController new];
        [self.navigationController pushViewController:vc animated:YES];
    }
    // 插屏广告
    if (indexPath.row == 3) {
        NSLog(@"点击%@",self.menuTitleArr[indexPath.row]);
        ADCDN_InterstitialViewController *vc = [ADCDN_InterstitialViewController new];
        [self.navigationController pushViewController:vc animated:YES];
        
    }
    // 模版视频广告
    if (indexPath.row == 4) {
        ADCDN_VideoViewController *vc = [ADCDN_VideoViewController new];
        vc.type = 2;
        [self.navigationController pushViewController:vc animated:YES];
    }
    
    // 游戏
    if (indexPath.row == 5) {
        /**
         * 注意事项：为提高用户体验，用户完成任务可以返回到游戏界面
         * 因此，游戏界面,将以 rootViewController.navigationController push出游戏界面,请确保rootViewController带有导航栏
         */
        /// 游戏模型
        ADCDN_GameModel *gameModel = [ADCDN_GameModel new];
        ///当前控制器（游戏控制器会隐藏导航栏，关闭游戏控制器时开发者需对导航栏做相应处理）
        gameModel.rootViewController = self;
        /// 开发者后台创建的游戏key
        gameModel.secretKey = KplcId_GameKey;
        /// 打开游戏
        [[ADCDN_GameManager shareManager] ADCDN_openGameWithModel:gameModel];
        __weak typeof(self) weakSelf = self;
        ///游戏内部自定义任务，回调通知app，开发者可以通过dict中的href字段判断是哪个任务，做相应的操作
        [[ADCDN_GameManager shareManager] ADCDN_gameNoticeAppOpenPage:^(NSDictionary * _Nonnull dict) {
        /// 记账任务
            if (dict[@"href"]) {
                if ([dict[@"href"] hasPrefix:@"com.fanmao.bookkeeping://chargeAccount"]) {
                    ADCDN_GameTaskViewController *vc = [ADCDN_GameTaskViewController new];
                    vc.dict = dict;
                    [weakSelf.navigationController pushViewController:vc animated:YES];
                }
            }
        }];

    }


}
@end
